<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>常见问题 - 汉中旅游</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/faq.css">
</head>
<body>
    <!-- 页面加载动画 -->
    <div class="page-loader">
        <div class="loader"></div>
    </div>

    <!-- 用户小部件 -->
    <div class="user-widget">
        <a href="login.html" id="login-link" class="btn btn-login">登录/注册</a>
        <div id="user-profile" style="display: none;">
            <img src="img/attractions/touxiang.jpg" alt="User Avatar" class="avatar">
            <span id="username-display"></span>
            <a href="#" id="logout-link" title="退出登录"><i class="fas fa-sign-out-alt"></i></a>
        </div>
    </div>

    <!-- 浮动导航菜单 -->
    <div class="float-nav">
        <button class="float-nav-toggle" id="floatNavToggle" title="快速导航">
            <i class="fas fa-bars"></i>
        </button>
        <div class="float-nav-menu" id="floatNavMenu">
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="jingdian.html">景点介绍</a></li>
                <li><a href="luxian.html">旅游线路</a></li>
                <li><a href="gonglue.html">旅游攻略</a></li>
                <li><a href="meishi.html">美食推荐</a></li>
                <li><a href="wenhua.html">汉文化活动</a></li>
                <li><a href="contact.html">联系我们</a></li>
                <li><a href="faq.html" class="active">常见问题</a></li>
            </ul>
        </div>
    </div>

    <!-- 导航栏 -->
    <nav>
        <div class="container">
            <div class="nav-container">
                <div class="nav-logo">
                    <a href="index.html">
                        <img src="img/attractions/logo.jpg" alt="汉中旅游" class="nav-logo-img">
                        <h2>汉中旅游</h2>
                    </a>
                </div>
                <ul class="main-nav">
                    <li><a href="index.html">首页</a></li>
                    <li><a href="jingdian.html">景点介绍</a></li>
                    <li><a href="luxian.html">旅游线路</a></li>
                    <li><a href="gonglue.html">旅游攻略</a></li>
                    <li><a href="meishi.html">美食推荐</a></li>
                    <li><a href="wenhua.html">汉文化活动</a></li>
                    <li><a href="contact.html">联系我们</a></li>
                    <li><a href="faq.html" class="active">常见问题</a></li>
                </ul>
                <!-- 用户操作区域已被移到独立的 user-widget 中 -->
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <main>
        <!-- 页面标题 -->
        <section class="page-header">
            <div class="container">
                <h1>常见问题</h1>
                <p>关于汉中旅游的常见问题解答</p>
            </div>
        </section>

        <!-- 问题分类导航 -->
        <section class="container">
            <div class="category-nav">
                <a href="#general" class="category-link">
                    <div class="category-icon"><i class="fas fa-info-circle"></i></div>
                    <span>基本信息</span>
                </a>
                <a href="#travel" class="category-link">
                    <div class="category-icon"><i class="fas fa-route"></i></div>
                    <span>出行交通</span>
                </a>
                <a href="#accommodation" class="category-link">
                    <div class="category-icon"><i class="fas fa-bed"></i></div>
                    <span>住宿问题</span>
                </a>
                <a href="#attractions" class="category-link">
                    <div class="category-icon"><i class="fas fa-mountain"></i></div>
                    <span>景点门票</span>
                </a>
                <a href="#shopping" class="category-link">
                    <div class="category-icon"><i class="fas fa-shopping-bag"></i></div>
                    <span>购物特产</span>
                </a>
                <a href="#other" class="category-link">
                    <div class="category-icon"><i class="fas fa-question-circle"></i></div>
                    <span>其他问题</span>
                </a>
            </div>
        </section>

        <!-- FAQ内容 -->
        <section class="container section-padding">
            <div class="faq-container">
                <!-- 基本信息 -->
                <div id="general" class="faq-section">
                    <h2 class="section-title">基本信息</h2>
                    <div id="general-faqs">
                        <p>正在加载基本信息...</p>
                    </div>
                </div>
                
                <!-- 出行交通 -->
                <div id="travel" class="faq-section">
                    <h2 class="section-title">出行交通</h2>
                    <div id="travel-faqs">
                        <p>正在加载交通信息...</p>
                    </div>
                </div>
                
                <!-- 住宿问题 -->
                <div id="accommodation" class="faq-section">
                    <h2 class="section-title">住宿问题</h2>
                    <div id="accommodation-faqs">
                        <p>正在加载住宿信息...</p>
                    </div>
                </div>
                
                <!-- 景点门票 -->
                <div id="attractions" class="faq-section">
                    <h2 class="section-title">景点门票</h2>
                    <div id="attractions-faqs">
                        <p>正在加载门票信息...</p>
                    </div>
                </div>

                <!-- 购物特产 -->
                <div id="shopping" class="faq-section">
                    <h2 class="section-title">购物特产</h2>
                    <div id="shopping-faqs">
                        <p>正在加载购物信息...</p>
                    </div>
                </div>

                <!-- 其他问题 -->
                <div id="other" class="faq-section">
                    <h2 class="section-title">其他问题</h2>
                    <div id="other-faqs">
                        <p>正在加载其他问题信息...</p>
                    </div>
                </div>
            </div>
        </section>
        
        <!-- 联系我们 -->
        <section class="container section-padding">
            <div class="faq-contact">
                <h2>没有找到您的问题？</h2>
                <p>如果您有其他问题，请随时联系我们，我们将竭诚为您服务。</p>
                <div class="contact-buttons">
                    <a href="contact.html" class="btn">联系我们</a>
                    <a href="tel:0916-123456" class="btn btn-outline"><i class="fas fa-phone"></i> 0916-123456</a>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>关于我们</h3>
                    <p>汉中旅游网致力于为游客提供最全面的汉中旅游信息，让您的汉中之行更加便捷、愉快。</p>
                    <div class="social-links">
                        <a href="#"><i class="fab fa-weibo"></i></a>
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <a href="#"><i class="fab fa-qq"></i></a>
                    </div>
                </div>
                <div class="footer-section">
                    <h3>快速链接</h3>
                    <ul>
                        <li><a href="index.html">首页</a></li>
                        <li><a href="jingdian.html">景点介绍</a></li>
                        <li><a href="luxian.html">旅游线路</a></li>
                        <li><a href="gonglue.html">旅游攻略</a></li>
                        <li><a href="contact.html">联系我们</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>热门景点</h3>
                    <ul>
                        <li><a href="jingdian.html#wuhoumu">武侯墓</a></li>
                        <li><a href="jingdian.html#nanhu">南湖</a></li>
                        <li><a href="jingdian.html#dingjunshan">定军山</a></li>
                        <li><a href="jingdian.html#guchengqiang">古城墙</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>联系方式</h3>
                    <p><i class="fas fa-map-marker-alt"></i> 地址：陕西省汉中市</p>
                    <p><i class="fas fa-phone"></i> 电话：0916-123456</p>
                    <p><i class="fas fa-envelope"></i> 邮箱：info@hanzhong-tourism.com</p>
                </div>
            </div>
        </div>
        <div class="footer-bottom">
            <div class="container">
                <p>&copy; 2023 汉中旅游网 版权所有</p>
            </div>
        </div>
    </footer>

    <script src="js/main.js"></script>
    <script src="js/script.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const API_URL = 'http://localhost:8080/api/faqs';

            // 渲染FAQ项目
            const renderFAQs = (faqs, containerId) => {
                const container = document.getElementById(containerId);
                if (!container) return;
                
                if (!faqs || faqs.length === 0) {
                    container.innerHTML = '<p>暂无相关问题。</p>';
                    return;
                }
                
                faqs.sort((a, b) => a.sortOrder - b.sortOrder);

                const faqHtml = faqs.map(faq => `
                    <div class="faq-item">
                        <div class="faq-question">
                            <h3>${faq.question}</h3>
                            <span class="toggle-icon"><i class="fas fa-plus"></i></span>
                        </div>
                        <div class="faq-answer">
                            <div class="faq-answer-content">
                                ${faq.answer}
                            </div>
                        </div>
                    </div>
                `).join('');

                container.innerHTML = faqHtml;
            };

            // 初始化手风琴功能
            const initAccordion = () => {
                const faqContainer = document.querySelector('.faq-container');
                if (!faqContainer) return;

                faqContainer.addEventListener('click', function(event) {
                    const questionHeader = event.target.closest('.faq-question');
                    if (!questionHeader) return;

                    const faqItem = questionHeader.parentElement;
                    const answer = faqItem.querySelector('.faq-answer');
                    const icon = questionHeader.querySelector('.toggle-icon i');

                    // 切换激活状态
                    const isActive = faqItem.classList.toggle('active');
                    
                    if (isActive) {
                        icon.classList.remove('fa-plus');
                        icon.classList.add('fa-minus');
                    } else {
                        icon.classList.remove('fa-minus');
                        icon.classList.add('fa-plus');
                    }
                });
            };
            
            // 主执行函数
            const main = async () => {
                try {
                    const response = await fetch(API_URL);
                    if (!response.ok) throw new Error('Failed to fetch FAQs');
                    const faqs = await response.json();

                    const categories = {
                        '基本信息': 'general-faqs',
                        '出行交通': 'travel-faqs',
                        '住宿问题': 'accommodation-faqs',
                        '景点门票': 'attractions-faqs',
                        '购物': 'shopping-faqs',
                        '其他': 'other-faqs'
                    };
                    
                    const groupedFaqs = faqs.reduce((acc, faq) => {
                        (acc[faq.category] = acc[faq.category] || []).push(faq);
                        return acc;
                    }, {});

                    for (const category in categories) {
                        renderFAQs(groupedFaqs[category], categories[category]);
                    }
                    
                    initAccordion();

                } catch (error) {
                    console.error('Error loading FAQs:', error);
                    const containers = ['general-faqs', 'travel-faqs', 'accommodation-faqs', 'attractions-faqs', 'shopping-faqs', 'other-faqs'];
                    containers.forEach(id => {
                        const el = document.getElementById(id);
                        if (el) el.innerHTML = '<p>加载常见问题失败，请稍后重试。</p>';
                    });
                }
            };
            
            main();

            // 平滑滚动到锚点
            document.querySelectorAll('a[href^="#"]').forEach(anchor => {
                anchor.addEventListener('click', function (e) {
                    e.preventDefault();
                    const target = document.querySelector(this.getAttribute('href'));
                    if (target) {
                        target.scrollIntoView({
                            behavior: 'smooth',
                            block: 'start'
                        });
                    }
                });
            });
        });
    </script>
    <style>
        /* 常见问题页面特定样式 */
    </style>
</body>
</html> 